package com.xiaoshuidi.cloud.module.member.controller.admin.invite;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.module.member.controller.admin.invite.vo.InviteActivityConfigVo;
import com.xiaoshuidi.cloud.module.member.controller.admin.invite.vo.InviteActivityLogVo;
import com.xiaoshuidi.cloud.module.member.controller.admin.invite.vo.InviteLogPageVo;
import com.xiaoshuidi.cloud.module.member.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.member.service.invite.InviteActivityConfigService;
import com.xiaoshuidi.cloud.module.member.service.invite.InviteActivityLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


/**
 * @description 租客银行卡
 * @author Leo Li
 * @date 2023-05-19 17:20:47
 * @version generator
 */
@Tag(name = "管理后台 - 邀请活动")
@RestController
@RequestMapping(ApiConstants.NAME+"/invite-activity")
@Validated
@Slf4j
public class InviteActivityController {
    @Resource
    InviteActivityConfigService inviteActivityConfigService;
    @Resource
    InviteActivityLogService inviteActivityLogService;

    @GetMapping("/get-valid-invite-config")
    @Operation(summary = "获取有效邀请配置")
    public CommonResult<InviteActivityConfigVo> getValidInviteConfig(){
        InviteActivityConfigVo vo = inviteActivityConfigService.getValidInviteConfig();
        if (ObjectUtils.isEmpty(vo)) {
            return CommonResult.success(new InviteActivityConfigVo());
        }
        return CommonResult.success(vo);
    }

    @PostMapping("/get-invite-log-page")
    @Operation(summary = "获取配置列表分页")
    public CommonResult<PageResult<InviteActivityLogVo>> listInviteLog(@Valid @RequestBody InviteLogPageVo form){
        PageResult<InviteActivityLogVo> page = inviteActivityLogService.getInviteActivityLogPage(form);
        return CommonResult.success(page);
    }

    @PostMapping("/set-invite-config")
    @Operation(summary = "更新配置")
    public CommonResult<Boolean> setInviteConfig(@Valid @RequestBody InviteActivityConfigVo form){
        inviteActivityConfigService.setInviteConfig(form);
        return CommonResult.success(Boolean.TRUE);
    }

}

